package logic

import (
	"context"
	"jingdong-product/productrpc/productrpc"

	"jingdong-product/api/internal/svc"
	"jingdong-product/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpdateLogic {
	return &ProductUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductUpdateLogic) ProductUpdate(req *types.ProductUpdateLoginRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.ProductRpc.ProductUpdate(l.ctx, &productrpc.ProductUpdateRequest{
		ProductTitle: req.ProductTitle,
		ProductImage: req.ProductImage,
		ProductPrice: float32(req.ProductPrice),
		ProductDesc:  req.ProductDesc,
		UserId:       req.UserId,
		ProductId:    req.ProductId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品更新成功",
		Code:    200,
		Data:    update,
	}, nil
}
